<%--
  Created by IntelliJ IDEA.
  User: admin
  Date: 2021/4/25
  Time: 11:07
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<div class="row" style="text-align: center">

    <c:if test="${roomInfo.pageNum+2<=roomInfo.pages}">
        <c:set var="start" value="${roomInfo.pageNum}"></c:set>
    </c:if>
    <c:if test="${roomInfo.pageNum+2>roomInfo.pages}">
        <c:set var="start" value="${roomInfo.pages-2}"></c:set>
    </c:if>

    <c:if test="${roomInfo.pageNum+2<=roomInfo.pages}">
        <c:set var="fin" value="${roomInfo.pageNum+2}"></c:set>
    </c:if>
    <c:if test="${roomInfo.pageNum+2>roomInfo.pages}">
        <c:set var="fin" value="${roomInfo.pages}"></c:set>
    </c:if>

    <ul class="pagination">
<%--        向左移--%>
        <c:if test="${roomInfo.pageNum-1>0}">
        <li><a href="javascript:nextPage(${roomInfo.pageNum-1})">&laquo;</a></li>
        </c:if>
        <c:if test="${roomInfo.pageNum-1<=0}">
            <li style="display: none"><a href="#">&laquo;</a></li>
        </c:if>

<%--        显示页码--%>
        <c:forEach begin= "${start>0?start:1}" end="${fin}" var="p">
            <c:if test="${roomInfo.pageNum == p}">
                <li class="active"><a href="javascript:nextPage(${p})">${p}</a></li>
            </c:if>
            <c:if test="${roomInfo.pageNum != p}">
                <li><a href="javascript:nextPage(${p})">${p}</a></li>
            </c:if>
        </c:forEach>

<%--    向右移--%>
        <c:if test="${roomInfo.pageNum<roomInfo.pages}">
            <li><a href="javascript:nextPage(${roomInfo.pageNum+1})">&raquo;</a></li>
        </c:if>

        <c:if test="${roomInfo.pageNum>=roomInfo.pages}">
            <li style="display: none"><a href="#">&raquo;</a></li>
        </c:if>
        <li class="danger"><a href="#">当前${roomInfo.pageNum}/共${roomInfo.pages}</a></li>
    </ul>

    <script>
     function nextPage(pageNow) {
         let buildingId = document.getElementById("buildingId").value;
         let roomNum = document.getElementById("roomNum").value;
         let capacity = document.getElementById("capacity").value;
         let statusId = document.getElementById("statusId").value;
         window.location ="/jkd/service/student/index?buildingId="+buildingId+"&roomNum="+roomNum+"&capacity="+capacity+"&statusId="+statusId+"&pageNow="+pageNow+"&count=1";
         // window.location ="/jkd/service/student/index?pageNow="+pageNow;
         // alert(pageNow);
     }
    </script>
</div>